package configuration

import (
	"encoding/json"
	"errors"
	"fmt"
	"kop/modules/configuration/client"
	"kop/util/log"
)

var ActivityPeerageConfigs []ActivityPeerageConf

func init() {

	if err := json.Unmarshal(client.Load("ActivityPeerage"), &ActivityPeerageConfigs); err != nil {
		panic(err)
	}

	log.Info("Load ActivityPeerage.json success.")
}

type ActivityPeerageConf struct {
	Peerage int32 `json:"ID"` // 基金ID
	AwardID int32 // 奖励ID
}

func GetByPeerage(peerage int32) (ActivityPeerageConf, error) {

	for _, v := range ActivityPeerageConfigs {
		if v.Peerage == peerage {
			return v, nil
		}
	}

	return ActivityPeerageConf{}, errors.New(fmt.Sprintf("ActivityPeerageConf not found [%d]", peerage))
}
